package com.imooc.mall.config;

import com.imooc.mall.filter.UserFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zwj
 * @Description: UserFilter配置类
 * @date 2022/10/30 12:03 上午
 */
@Configuration
public class UserFilterConfig {

    @Bean
    public UserFilter getUserFilter(){
        return new UserFilter();
    }

    @Bean(name = "userFilterConf")
    public FilterRegistrationBean userFilterConfig(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        //注册拦截器
        registrationBean.setFilter(getUserFilter());
        //添加拦截规则
        registrationBean.addUrlPatterns("/cart/*");
        registrationBean.addUrlPatterns("/order/*");
        registrationBean.setName("userFilterConf");
        return registrationBean;
    }
}
